package domain

import (
	"github.com/shirou/gopsutil/mem"
	"log"
)

/**
内存信息
*/
type Memory struct {
	Total       uint64  `json:"total"`       //总数
	Available   uint64  `json:"available"`   // 可用
	Used        uint64  `json:"used"`        //已用
	UsedPercent float64 `json:"usedPercent"` //使用占比
}

func (memory *Memory) MemoryInfo() error {

	//{"total":8129818624,"available":4193423360,"used":3936395264,"usedPercent":48,"free":0,"active":0,"inactive":0,...}
	infoMem, err := mem.VirtualMemory()
	if err != nil {
		log.Println("获取内存信息失败：", err)
		return err
	}
	log.Println("获取内存信息成功，当前机器的内存信息为:", infoMem)
	memory.Total = infoMem.Total
	memory.Available = infoMem.Available
	memory.Used = infoMem.Used
	memory.UsedPercent = infoMem.UsedPercent
	return nil

}
